package com.sthz.facepay.mapper;

import com.sthz.facepay.model.Recharge;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.apache.ibatis.type.JdbcType;

public interface RechargeMapper {
    @Delete({
        "delete from st_recharge",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into st_recharge (id, aid, ",
        "money, advertisement, ",
        "data_time, operator)",
        "values (#{id,jdbcType=INTEGER}, #{aid,jdbcType=INTEGER}, ",
        "#{money,jdbcType=DOUBLE}, #{advertisement,jdbcType=VARCHAR}, ",
        "#{data_time,jdbcType=TIMESTAMP}, #{operator,jdbcType=VARCHAR})"
    })
    int insert(Recharge record);

    @InsertProvider(type=RechargeSqlProvider.class, method="insertSelective")
    int insertSelective(Recharge record);

    @Select({
        "select",
        "id, aid, money, advertisement, data_time, operator",
        "from st_recharge",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="aid", property="aid", jdbcType=JdbcType.INTEGER),
        @Result(column="money", property="money", jdbcType=JdbcType.DOUBLE),
        @Result(column="advertisement", property="advertisement", jdbcType=JdbcType.VARCHAR),
        @Result(column="data_time", property="data_time", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="operator", property="operator", jdbcType=JdbcType.VARCHAR),
        @Result(column="aid", property="Agent", one=@One(select="com.sthz.facepay.mapper.AgentMapper.getById",fetchType = FetchType.EAGER))
    })
    Recharge selectByPrimaryKey(Integer id);

    @UpdateProvider(type=RechargeSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Recharge record);

    @Update({
        "update st_recharge",
        "set aid = #{aid,jdbcType=INTEGER},",
          "money = #{money,jdbcType=DOUBLE},",
          "advertisement = #{advertisement,jdbcType=VARCHAR},",
          "data_time = #{data_time,jdbcType=TIMESTAMP},",
          "operator = #{operator,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Recharge record);
}